//
//  LYPhoto.m
//  LYPhotoBrowser
//
//  Created by LvYuan on 16/12/12.
//  Copyright © 2016年 LvYuan. All rights reserved.
//

#import "LYPhoto.h"
#import "UIImageView+WebCache.h"
@implementation LYPhoto

- (UIImage *)thumbImage{
    if (_thumbImage) {
        return _thumbImage;
    }
    _thumbImage = [[SDWebImageManager sharedManager] diskImageExistsForURL:[NSURL URLWithString:self.thumbPicUrl]]?[[SDImageCache sharedImageCache]imageFromDiskCacheForKey:self.thumbPicUrl]:nil;
    if (!_thumbImage) {//如果为nil 反回一个代码生成的image
        return [LYPhoto placeHolderFillColorImage];
    }
    return _thumbImage;
}

+ (UIImage *)placeHolderFillColorImage{
    CGSize imageSize =CGSizeMake(2,2);
    UIGraphicsBeginImageContextWithOptions(imageSize,0, [UIScreen mainScreen].scale);
    [[UIColor colorWithWhite:0.1 alpha:1] set];
    UIRectFill(CGRectMake(0,0, imageSize.width, imageSize.height));
    UIImage *pressedColorImg =UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return pressedColorImg;
}

@end
